package com.usian.emp.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.usian.emp.bean.Emp;
import com.usian.emp.service.EmpService;
import com.usian.util.MD5Utils;
/**
 * @author li
 * 	控制层
 * @version  0.0.1
 * */
@RequestMapping("/emp")
@Controller
public class EmpAction {
	@Autowired
	private EmpService empService ;
	/**
	 * 登陆
	 * */
	@RequestMapping("/findlogin")
	public String findlogin(Emp emp, Model model ,HttpServletRequest request){
		String p = emp.getPwd();
		String md5 = MD5Utils.md5(p);
		emp.setPwd(md5);
		Emp find = empService.findlogin(emp);
		if(find==null){
			model.addAttribute("msgcode","账号或密码不正确！");
			return "forward:/jsp/login.jsp";
		}
		request.getSession().setAttribute("username", find.getUserName());
		request.getSession().setAttribute("unameid", find.getUuid());
		return "redirect:/index.jsp";
	}
	/**
	 * 注销
	 * */
	@RequestMapping("/exitUser")
	public String exitUser(HttpServletRequest request,  Model model){
		System.out.println("asdasd");
		request.getSession().invalidate();
		return "redirect:/jsp/login.jsp";
	}

}
